﻿@*
   Copyright (c) Microsoft. All rights reserved.
   Licensed under the MIT license. See LICENSE file in the project root for full license information.
*@

@model Microsoft.Fx.Portability.Reports.Html.CompatibilitySummaryModel

@using Microsoft.Fx.Portability
@using Microsoft.Fx.Portability.Reports.Html
@using Microsoft.Fx.Portability.Reports.Html.Resources
@using System.Linq

@{
    var majorIssues = Model.Breaks.Where(b => b.Key.ImpactScope == BreakingChangeImpact.Major && !b.Key.IsRetargeting);
    var minorIssues = Model.Breaks.Where(b => b.Key.ImpactScope == BreakingChangeImpact.Minor && !b.Key.IsRetargeting);
    var edgeIssues = Model.Breaks.Where(b => b.Key.ImpactScope == BreakingChangeImpact.Edge && !b.Key.IsRetargeting);
    var totalCompatIssues = majorIssues.Count() + minorIssues.Count() + edgeIssues.Count();
    var majorRetargetingIssues = Model.Breaks.Where(b => b.Key.ImpactScope == BreakingChangeImpact.Major && b.Key.IsRetargeting);
    var minorRetargetingIssues = Model.Breaks.Where(b => b.Key.ImpactScope == BreakingChangeImpact.Minor && b.Key.IsRetargeting);
    var edgeRetargetingIssues = Model.Breaks.Where(b => b.Key.ImpactScope == BreakingChangeImpact.Edge && b.Key.IsRetargeting);
    var totalRetargetingIssues = majorRetargetingIssues.Count() + minorRetargetingIssues.Count() + edgeRetargetingIssues.Count();

    var runtimeIssuesDivId = Guid.NewGuid().ToString();
    var runtimeHeaderDivId = Guid.NewGuid().ToString();
    var retargetingHeaderDivId = Guid.NewGuid().ToString();
    var retargetingIssuesDivId = Guid.NewGuid().ToString();
}

@if (totalCompatIssues + totalRetargetingIssues > 0)
{
    @* role attributes are required for IE to allow a span reference in aria-labelledby *@
    <span class="invisibleText" id="@LocalizedStrings.Collapse" role="">@LocalizedStrings.Collapse</span>
    <span class="invisibleText" id="@LocalizedStrings.Expand" role="">@LocalizedStrings.Expand</span>

    <div>
        @if (Model.Assembly != null)
        {
            <h3 id="Compat-@Model.Assembly" tabindex="0">
                    <span class="assembly-name">@Model.ReportingResult.GetNameForAssemblyInfo(Model.Assembly)</span>
                    @if (!string.IsNullOrEmpty(Model.Assembly.TargetFrameworkMoniker))
                    {
                        <span class="assembly-tfm">(@Model.Assembly.TargetFrameworkMoniker)</span>
                    }
            </h3>
        }
        <h3>
            <span class="CompatIssuesHeader" id="@runtimeHeaderDivId" role="">@LocalizedStrings.RuntimeCompatibilityIssues (@totalCompatIssues)</span>
            <button class="ToggleButton" id="hide-@runtimeIssuesDivId" title="@LocalizedStrings.Collapse" aria-labelledby="@runtimeHeaderDivId @LocalizedStrings.Collapse">&#8212;</button>
            <button class="ToggleButton" id="show-@runtimeIssuesDivId" title="@LocalizedStrings.Expand" aria-labelledby="@runtimeHeaderDivId @LocalizedStrings.Expand" style="display: none">+</button>
        </h3>
        <div id="@runtimeIssuesDivId">
            <p>@LocalizedStrings.RuntimeCompatIssueDescription</p>
            @Html.Partial("_CompatibilityResults", new CompatibilityResultsModel(LocalizedStrings.MajorCompatibilityIssues, LocalizedStrings.MajorCompatIssueDescription, majorIssues, 0, 2))
            @Html.Partial("_CompatibilityResults", new CompatibilityResultsModel(LocalizedStrings.MinorCompatibilityIssues, LocalizedStrings.MinorCompatIssueDescription, minorIssues, 0, 3))
            @Html.Partial("_CompatibilityResults", new CompatibilityResultsModel(LocalizedStrings.EdgeCompatibilityIssues, LocalizedStrings.EdgeCompatIssueDescription, edgeIssues, 0, 100))
        </div>
        <h3>
            <div class="CompatIssuesHeader" id="@retargetingHeaderDivId" role="">@LocalizedStrings.RetargetingCompatibilityIssues (@totalRetargetingIssues)</div>
            <button class="ToggleButton" id="hide-@retargetingIssuesDivId" title="@LocalizedStrings.Collapse" aria-labelledby="@retargetingHeaderDivId @LocalizedStrings.Collapse" style="display: none">&#8212;</button>
            <button class="ToggleButton" id="show-@retargetingIssuesDivId" title="@LocalizedStrings.Expand" aria-labelledby="@retargetingHeaderDivId @LocalizedStrings.Expand">+</button>
        </h3>
        <div class="BeginToggledOff" id="@retargetingIssuesDivId">
            <p>@Html.Raw(LocalizedStrings.RetargetingCompatIssueDescriptionPart1)</p>
            <p>@Html.Raw(LocalizedStrings.RetargetingCompatIssueDescriptionPart2)</p>
            @Html.Partial("_CompatibilityResults", new CompatibilityResultsModel(LocalizedStrings.MajorRetargetingIssues, LocalizedStrings.MajorCompatIssueDescription, majorRetargetingIssues, 0, 2))
            @Html.Partial("_CompatibilityResults", new CompatibilityResultsModel(LocalizedStrings.MinorRetargetingIssues, LocalizedStrings.MinorCompatIssueDescription, minorRetargetingIssues, 0, 3))
            @Html.Partial("_CompatibilityResults", new CompatibilityResultsModel(LocalizedStrings.EdgeRetargetingIssues, LocalizedStrings.EdgeCompatIssueDescription, edgeRetargetingIssues, 0, 100))
        </div>
    </div>
    <p>
        <a href="#@LocalizedStrings.CompatibilityPageTitle">@LocalizedStrings.BackToSummary</a>
    </p>
    <br />
}
